package cn.edu.nju.software.cdiy.algorithm.performance;

import cn.edu.nju.software.cdiy.bean.Memory;
import cn.edu.nju.software.cdiy.util.Constant;

public class MemoryEvaluator implements Evaluator<Memory>{

	@Override
	public double getPerformance(Memory t) {
		double score = 0;
		
		//内存类型得分
		String memType = t.getMemType().getValue();
		double memTypeScore = getMemTypeBase(memType)*Constant.MEM_STD_MEMTYPE;
		
		//内存频率得分
		int memFrequency = t.getMemFrequency().getKey();
		double memFrequencyScore = getMemFrequencyBase(memFrequency)*Constant.MEM_STD_MEMFREQUENCY;
		
		//内存容量得分
		String memCapacity = t.getMemCapacity().getValue();
		double memCapacityScore = getMemCapacityBase(memCapacity)*Constant.MEM_STD_MEMCAPACITY;
		
		
		score = memTypeScore+memFrequencyScore+memCapacityScore;
		return score;
	}

	private double getMemCapacityBase(String memCapacity) {
		/*
		 * 内存容量基础分
		 * 256MB		50
		 * 512MB		60
		 * 1G			70
		 * 2G			75
		 * 4G			80
		 * 8G			90
		 * */
		if(memCapacity.equals("256MB"))
			return 50;
		else if(memCapacity.equals("512MB"))
			return 60;
		else if(memCapacity.equals("1GB"))
			return 70;
		else if(memCapacity.equals("2GB"))
			return 75;
		else if(memCapacity.equals("4GB"))
			return 80;
		else if(memCapacity.equals("8GB"))
			return 90;
		else return 95;
	}

	private double getMemFrequencyBase(int memFrequency) {
		/*
		 * 内存频率基础分
		 * 248-250			50
		 * 245-247			60
		 * 242-244			70
		 * 239-241			80
		 * 236-238			90
		 * */
		if(memFrequency>=248 && memFrequency<=250)
			return 50;
		else if(memFrequency>=245 && memFrequency<=247)
			return 60;
		else if(memFrequency>=242 && memFrequency<=244)
			return 70;
		else if(memFrequency>=239 && memFrequency<=241)
			return 80;
		else if(memFrequency>=236 && memFrequency<=238)
			return 90;
		else return 95;
	}

	private double getMemTypeBase(String memType) {
		/*
		 * 内存类型基础分
		 * DDR			60
		 * DDR2			75
		 * DDR3			90
		 * */
		if(memType.equals("DDR"))
			return 60;
		else if(memType.equals("DDR2"))
			return 75;
		else if(memType.equals("DDR3"))
			return 90;
		else return 95;
	}

}
